package com.qf.controller;

import com.qf.entity.Diaries;
import com.qf.service.DiariesService;
import com.qf.vo.R;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 日记相关接口
 */
@RestController
@RequestMapping("diaries")
@Tag(name = "日记模块")
public class DiariesController {
    /**
     * 服务对象
     */
    @Resource
    private DiariesService diariesService;

    /**
     * 新增日记
     *
     * @param diaries
     * @return R
     */
    @PostMapping("add")
    public R add(@RequestBody Diaries diaries) {


        return R.ok(diariesService.addDiaries(diaries));
    }

    /**
     * 根据日记Id来删除日记
     *
     * @param id
     * @return
     */
    @GetMapping("deleteById")
    public R deleteById(@RequestBody Diaries diaries) {
        return diariesService.deleteDiaries(diaries);

    }

    /**
     * 根据日记id来修改日记内容
     *
     * @param id
     * @return
     */
    @PutMapping("updateDiaries")
    public R updateDiaries(@RequestBody Diaries diaries) {
        return diariesService.updateDiaries(diaries);


    }

    /**
     * 根据日记的每个属性来动态查询日记
     *
     * @param userId
     * @return
     */
    @GetMapping("selectByDiaries")
    public R<List<Diaries>> selectByDiaries( Integer userId) {
        return diariesService.selectDiaries(userId);

    }


}

